package com.hualan.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hualan.mapper.FmMapper;
import com.hualan.pojo.FM;
import com.hualan.pojo.PageResult;
import com.hualan.pojo.Result;
import com.hualan.service.FMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FMServiceImpl implements FMService {
    @Autowired
    private FmMapper fmMapper;
    @Override
    public PageResult<FM> queryAllFm(String title, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<FM> fmList = fmMapper.queryAllFm(title);
        Page<FM> p = (Page<FM>) fmList;
        return new PageResult<>(p.getTotal(),p.getResult());
    }

    @Override
    public Result addFm(FM fm) {
        try {
            fmMapper.addFm(fm);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("添加失败");
        }
    }

    @Override
    public Result updateFm(FM fm) {
        try {
            fmMapper.updateFm(fm);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("更新失败");
        }
    }

    @Override
    public Result deleteFm(List<Integer> ids) {
        try {
            fmMapper.deleteFm(ids);
            return Result.success();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("删除失败");
        }
    }


}
